import {
  Component,
  ViewChild,
  Injector,
  Output,
  EventEmitter
} from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap';
import {
  TechRuleListDto,
  TechRuleServiceProxy,
  StockOperationLogListDto
} from '@shared/service-proxies/service-proxies';
import { AppComponentBase } from '@shared/common/app-component-base';
import { Paginator, LazyLoadEvent } from 'primeng/primeng';

import { Table } from 'primeng/table';

@Component({
  selector: 'TechRuleLogModal',
  templateUrl: './techrule-log-modal.component.html'
})
export class TechRuleLogModalComponent extends AppComponentBase {
  @ViewChild('createOrEditModal') modal: ModalDirective;
  @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();

  active = false;
  saving = false;

  techrule = new TechRuleListDto();
  advancedFiltersAreShown = false;
  filterText = '';

  logs = new Array<StockOperationLogListDto>();

  constructor(
    injector: Injector,
    private _techruleService: TechRuleServiceProxy
  ) {
    super(injector);
  }

  show(techrule: TechRuleListDto): void {
    this.techrule = techrule;
    this.active = true;
    this.modal.show();
    this.getTechRuleLogs();
  }

  getTechRuleLogs() {
    this.primengTableHelper.showLoadingIndicator();
    this._techruleService
      .getTechRuleLogs(
        this.techrule.id,
        this.filterText,
        undefined,
        undefined,
        1000,
        0
      )
      .subscribe(result => {
        this.logs=result.items;
        this.primengTableHelper.hideLoadingIndicator();
      });
  }

  close(): void {
    this.active = false;
    this.modal.hide();
  }
}
